package com.cgsd.heyu.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.cgsd.heyu.ui.BaseFragment;

import java.util.List;

/**
 * @author xiaoxing
 * Description 公用viewpager适配器
 * CreateData: 2020/11/3
 */
public class Vp2FragAdapter extends FragmentStateAdapter {
    private List<BaseFragment> fragments;

    public Vp2FragAdapter(@NonNull FragmentActivity fragmentActivity,List<BaseFragment> fragments) {
        super(fragmentActivity);
        this.fragments = fragments;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments == null ? 0 : fragments.size();
    }
}
